package com.erp.servlet;

import com.erp.bean.*;
import com.erp.service.*;
import com.erp.service.impl.EntrepotServiceImpl;
import com.erp.util.factroy.ObjectFactory;
import com.mysql.cj.x.protobuf.MysqlxCrud;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author lyb
 * 入库订单泪飙控制器
 */
@WebServlet("/entrylist.action")
public class EntrylistServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println(1);
        OrderService orderService = ObjectFactory.getServiceInstance("com.erp.service.impl.OrderServiceImpl", OrderService.class);
        EmpService empService = ObjectFactory.getServiceInstance("com.erp.service.impl.EmpServiceImpl",EmpService.class);
        CommodityService commodityService = ObjectFactory.getServiceInstance("com.erp.service.impl.CommodityServiceImpl", CommodityService.class);
        OrderStateService stateService = ObjectFactory.getServiceInstance("com.erp.service.impl.OrderStateServiceImpl", OrderStateService.class);
        List<Order> list = orderService.findAll();

        List<Order> orders=new ArrayList<Order>();
        for (Order od:list){
            if (od.getSid()==6){
                orders.add(od);
            }
        }
        //创建仓库逻辑对象
        EntrepotService entrepotService =new EntrepotServiceImpl();
        List<Entrepot> Entrepots=entrepotService.findAll();
        List<Emp>  emps = empService.finAll();
        List<Commodity>  commodities = commodityService.findAll();
        List<OrderState>  states = stateService.findAll();
        //将订单列表保存到request
        req.setAttribute("orders",orders);
        req.setAttribute("emps",emps);
        req.setAttribute("commodities",commodities);
        req.setAttribute("states",states);
        req.setAttribute("Entrepots",Entrepots);
        //转发到列表页面显示
        req.getRequestDispatcher("entrylist.jsp").forward(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
